const state = {
  systemInfo: {},
  statusBarHeight: 0,
  navBarHeight: 44,
  loading: false,
  networkStatus: true
}

const mutations = {
  SET_SYSTEM_INFO(state, systemInfo) {
    state.systemInfo = systemInfo
    state.statusBarHeight = systemInfo.statusBarHeight || 0
    // iOS导航栏高度为44px，Android为48px
    state.navBarHeight = systemInfo.platform === 'ios' ? 44 : 48
  },
  
  SET_LOADING(state, loading) {
    state.loading = loading
  },
  
  SET_NETWORK_STATUS(state, status) {
    state.networkStatus = status
  }
}

const actions = {
  setSystemInfo({ commit }, systemInfo) {
    commit('SET_SYSTEM_INFO', systemInfo)
  },
  
  setLoading({ commit }, loading) {
    commit('SET_LOADING', loading)
  },
  
  setNetworkStatus({ commit }, status) {
    commit('SET_NETWORK_STATUS', status)
  }
}

const getters = {
  systemInfo: state => state.systemInfo,
  statusBarHeight: state => state.statusBarHeight,
  navBarHeight: state => state.navBarHeight,
  totalNavHeight: state => state.statusBarHeight + state.navBarHeight,
  loading: state => state.loading,
  networkStatus: state => state.networkStatus
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}